package com.masterclient.app.modules.timelimited.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.managerlibrary.netsign.NetEnvManager;
import com.masterclient.app.httpservice.RetrofitUtil;
import com.masterclient.app.modules.timelimited.model.TimeLimitedTabBean;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class TimeLimitedTabContractPresenter extends TimeLimitedTabContract.Presenter {


    @Override
    public void getTabData() {

        String url = NetEnvManager.BASE_SURL+"2/" + "time_preference.html";

        Observable<TimeLimitedTabBean> observable = RetrofitUtil.getInstance().getTimeLimitedTab(url);

        Disposable disposable = toSubscribe(observable, new Consumer<TimeLimitedTabBean>() {
            @Override
            public void accept(@NonNull TimeLimitedTabBean bean) throws Exception {
                if("0".equals(bean.getCode())){
                    mView.showData(bean.getData());
                }else {
                    mView.loadFail(bean.getMsg());
                }
            }
        },new ThrowableConsumer(){
            @Override
            public void accept(Throwable o) throws Exception {
                super.accept(o);
                mView.loadFail("网络异常，请重试");
            }
        });
        mRxManager.add(disposable);

    }
}
